package cn.jingyuan.swan.system.web.config;

import cn.jingyuan.swan.cloud.mapping.ApiResourceScanHandler;
import cn.jingyuan.swan.cloud.mapping.SpringBootApiResourceScanHandler;
import cn.jingyuan.swan.cloud.web.DefaultWebMvcConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AppWebConfig {

    @Bean
    public DefaultWebMvcConfiguration webMvcConfig() {
        return new DefaultWebMvcConfiguration();
    }

    @Bean
    @ConditionalOnMissingBean(ApiResourceScanHandler.class)
    public ApiResourceScanHandler apiResourceScanHandler() {
        List<String> urls = new ArrayList<>();
        urls.add("/error");

        SpringBootApiResourceScanHandler mappingScan = new SpringBootApiResourceScanHandler();
        mappingScan.enableScan();
        mappingScan.addIgnoreScanUrls(urls);
        return mappingScan;
    }

}
